$(function () {
	let form = layui.form;
	form.verify({
		pwd: [/^[\S]{6,12}$/, '密码必须6到12位,且不能出现空格'],
		oldPwd: value => {
			let oldPwd = $('.pwd-update [name="oldPwd"]').val();
			if (oldPwd == value) return '新密码不能与原密码相同';
		},
		newPwd: value => {
			let newPwd = $('.pwd-update [name="newPwd"]').val();
			if (newPwd !== value) return '两次密码不一致';
		}
	});

	$('.pwd-update').on('submit', function (e) {
		e.preventDefault();
		$.ajax({
			url: '/my/updatepwd',
			method: 'post',
			data: $(this).serialize(),
			success: res => {
				if (res.status != 0) return layer.msg(res.message);
				layer.msg(res.message);
				$('.pwd-update [type="reset"]').click();
			}
		});
	});
});